<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数防抖动</title>
    <style>
        input {
            width: 500px;
            height: 50px;
        }
    </style>
</head>

<body>
    <input type="text">

</body>

<script>
    var inp = document.querySelector("input");
    // var t = null;
    // inp.addEventListener("keyup", function (e) {
    //     clearTimeout(t);
    //     t = setTimeout(function () {
    //         console.log(inp.value);
    //     }, 300);
    // })

    inp.addEventListener("keyup", (function (e) {
        var t = null;
        return function () {
            clearTimeout(t);
            t = setTimeout(function () {
                console.log(inp.value);
            }, 500);
        }
    }()))


    // function(e){}()








</script>

</html>